#ifndef PRODUCT_MODEL_H
#define PRODUCT_MODEL_H
#include "product.h"
#include <QAbstractTableModel>
#include <QSqlQueryModel>


class ProductModel : public QSqlQueryModel {
    Q_OBJECT

public:
    explicit ProductModel(QObject *parent = nullptr);
    
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    
    void refresh();
    bool addProduct(const Product &product);
    bool updateProduct(const Product &product);
    bool deleteProduct(int productId);
    Product getProductById(int productId);
    void setFilter(const QString &filter);
private:
    enum Column {
        Id = 0,
        Name,
        Barcode,
        Price,
        Cost,
        Stock,
        MinStock,
        Category,
        Supplier,
        ColumnCount
    };
    QString currentFilter;  // 添加过滤器成员变量
};

#endif // PRODUCT_MODEL_H
